home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-05-04 | 2.2 KB | 44 lines | [TEXT/GEOL] |
- Item 7403182 28-April-90 20:12PDT
-
- From: MIKE.VILOT ObjectWare, Michael Vilot,PRT
-
- To: DEREK White, Derek
-
- cc: CPLUS.DEV$ C++ Interest List--Developers
- CPLUS.APPLE$ C++ Interest List--Apple Employees
-
- Sub: Re: Value parameter…
-
- Derek,
- In C and C++ arguments are passed by value. Pointers are passed by
- value, but they denote other objects -- hence the use of pointer arguments
- for side-effects in C.
- C++ needs to balance a few different concerns. The first is that it
- should be possible to define and use objects of user-defined classes that
- behave much the same as objects of the builtin types. Thus, if I define
- a class complex, and create a few complex instances, it would be nice if
- they acted more or less like int objects or float objects. SO, the default
- is to copy the object into and out of the function call (think about the
- implication of this for large objects).
- Next, C++ supports object-oriented programming. That means supporting
- polymorphism. It does so through virtual functions. However, there are
- significant differences to the ways Object Pascal and C++ handle the binding
- of polymorphic calls. Because ...
- Third, C++ tries to maintain the efficiency of C whenever possible. One
- implication of this is that static binding of virtual calls is allowed. That
- means that if the translator can detect that a given object will always have
- the same type, it can treat a virtual function call just like a regular one.
- This can be useful for certain performance-critical O-O programs.
- To maintain polymorhic behavior without resorting to pointers (and their
- awkward syntax), you can make one simple change: declare your argument to
- be a _reference_ to the base class (i.e.: void valtest(TShape& s)), and you
- will find the behaviour working the way you would like.
- An additional benefit is that the object as a whole will not be copied
- into the function, only a reference to it. All references are the same size,
- independent of the size of the object it references (yes, it's implemented
- as a pointer, but _your_ code doesn't have to manipulate them).
-
- Hope this helps,
- Mike
-
-